/* eslint valid-jsdoc: "off" */
'use strict';

require('dotenv').config();
const path = require('path');

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
    /**
     * built-in config
     * @type {Egg.EggAppConfig}
     **/
    const config = exports = {};

    // use for cookie sign key, should change to your own and keep security
    config.keys = `${appInfo.name}_1609732517889_1990`;

    // add your middleware config here
    config.middleware = [
        'exceptions', // 错误处理
    ];

    // add your user config here
    const userConfig = {
        // myAppName: 'egg',
    };

    // 静态资源配置
    // https://github.com/eggjs/egg-static
    config.static = {
        dir: [
            { prefix: '/apidoc', dir: path.join(appInfo.baseDir, 'app/public/apidoc/') },
        ],
        dynamic: true,
        preload: false,
    };

    // 跨域配置
    config.cors = {
        allowMethods: 'GET,HEAD,PUT,POST,DELETE,OPTIONS',
        credentials: true,
    };

    // csfr token 字段配置
    config.security = {
        csrf: false,
        domainWhiteList: [
            'http://127.0.0.1:3000', // nuxt 默认端口
            'http://127.0.0.1:7001', // eggjs 默认端口
            'http://127.0.0.1:9528', // vue-admin-template 默认端口
            'http://localhost:9528', // vue-admin-template 默认端口
        ],
    };

    // 文件上传配置
    config.multipart = {
        mode: 'file',
    };

    // 开启前置代理模式
    config.proxy = true;
    config.ipHeaders = 'X-Real-Ip, X-Forwarded-For';

    return {
        ...config,
        ...userConfig,
    };
};
